package world.ztomorrow.jzyhainan.common;

import lombok.RequiredArgsConstructor;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Component
@RequiredArgsConstructor
public class ZtCrawler {

    private final AnalysisService analysisService;

    /**
     * 根据URL获取页面
     */
    public void crawler(String url) {
        // 设置 ChromeDriver 路径（确保驱动程序与 Chrome 版本一致）
        System.setProperty("webdriver.chrome.driver", "D:/javaProject/jzy-hainan/src/main/resources/chromedriver/chromedriver.exe");

        // 初始化 WebDriver（Chrome 浏览器）
        WebDriver driver = new ChromeDriver();

        // 打开目标页面
        driver.get(url);

        analysis(driver);
    }

    /**
     * 解析获取的数据
     */
    public void analysis(WebDriver driver) {
        analysisService.work(driver);
    }
}
